export function getCurrentDayOfWeek() {  
    const daysOfWeek = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];  
    const currentDate = new Date();  
    const dayOfWeekIndex = currentDate.getDay();  
      
    return daysOfWeek[dayOfWeekIndex];  
}  

export function removeHtmlTags(text) {
  return text.replace(/<[^>]*>/g, '');
}


// 传入时间戳，返回天数
export function getDaysFromTimestamp(timestamp) {
  const now = new Date().getTime();
  const diff = now - timestamp;
  const days = Math.floor(diff / (1000 * 60 * 60 * 24)) + 1;
  return days;
}

// 将传入的时间戳转换为日期格式，例如：2023-01-01 12:01:12  也可以使用 momentjs.cn
export function formatDate(timestamp) {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  const hours = String(date.getHours()).padStart(2, '0');	
  const minutes = String(date.getMinutes()).padStart(2, '0');
  const seconds = String(date.getSeconds()).padStart(2, '0');
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

export function formatDateDay(timestamp) {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}

export function formatDateHour(timestamp) {
	const date = new Date(timestamp);
  const hours = String(date.getHours()).padStart(2, '0');	
  const minutes = String(date.getMinutes()).padStart(2, '0');
  const seconds = String(date.getSeconds()).padStart(2, '0');
  return `${hours}${minutes}${seconds}`;
}

// 性别格式化 0-保密 1-男 2-女
export function formatGender(gender) {
  const genderMap = {
    0: '保密',
    1: '男',
    2: '女'
  };
  return genderMap[gender] || '未知';
}

// 超出指定字符串长度，后面的显示省略号
export function truncateStr(str, maxLength) {
	if (!str) {
    return '';
  }
  if (str.length <= maxLength) {
    return str;
  }
  return str.slice(0, maxLength) + '...';
}

// 判断是否是管理员角色
export function isAdminRole(role) {
	const u = uniCloud.getCurrentUserInfo()
  return u.role.includes('admin')
}
